package com.xzx.mr.inputformat;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.JobContext;
import org.apache.hadoop.mapreduce.RecordReader;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;

import java.io.IOException;

/**
 * 自定义的inputFormat
 * @author xinzhixuan
 * @version V1.0
 * @date 2019/7/20 21:12
 */
public class WholeFileInputFormat extends FileInputFormat<Text, BytesWritable> {

    /**
     * 返回false，表示文件不用切割
     */
    @Override
    protected boolean isSplitable(JobContext context, Path filename) {
        return false;
    }


    @Override
    public RecordReader<Text, BytesWritable> createRecordReader(InputSplit split, TaskAttemptContext context) throws
            IOException, InterruptedException {
        RecordReader<Text, BytesWritable> recordReader = new WholeRecorderReader();
        recordReader.initialize(split, context);
        return recordReader;
    }
}
